<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/18 0018
 * Time: 10:15
 */

namespace app\api\controller\v1;


use app\currency\service\AccessTokenService;
use library\Controller;

class RefreshToken extends Controller
{
    /**
     * @param $id
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function read($id)
    {
        $id = strtolower($id);//所有转换为小写
        if(!in_array($id,['member','cleaner','agent']))
        {
            throw new \think\Exception("client {$id} not found");
        }
        $refresh_token = $this->request->get('refresh_token','');
        $result = AccessTokenService::refreshToken($refresh_token, $id);
        if(isset($result['code'])){
            $this->error($result['msg'],'', $result['code']);
        }
        $this->success('刷新access_token成功！', $result);
    }
}